package com.lagou.edu.context;

import com.lagou.edu.context.stereotype.Component;
import com.lagou.edu.context.stereotype.Controller;
import com.lagou.edu.context.stereotype.Repository;
import com.lagou.edu.context.stereotype.Service;

import java.util.Set;

/**
 * @Author zhaozuowen
 * @Description
 * @Date 2020-01-12 17:30
 **/

public class SimpleBeanNameGenerater implements BeanNameGenerater {

    @Override
    public String getBeanName(MetadataReader reader) {
        String beanName="";
        Set<String> annotationSet = reader.getAnnotationSet();
        for (int i = 0; i < annotationSet.size(); i++) {
              if(annotationSet.equals(Component.class.getName())){
                  Component annotation = reader.getClasses().getAnnotation(Component.class);
                  beanName= annotation.value();
                  break;
              }else if(annotationSet.equals(Service.class.getName())){
                  Service annotation = reader.getClasses().getAnnotation(Service.class);
                  beanName= annotation.value();
                  break;
              }else if(annotationSet.equals(Repository.class.getName())){
                  Repository annotation = reader.getClasses().getAnnotation(Repository.class);
                  beanName= annotation.value();
                  break;
              }
              else if(annotationSet.equals(Controller.class.getName())){
                  Controller annotation = reader.getClasses().getAnnotation(Controller.class);
                  beanName= annotation.value();
                  break;
              }
        }
        if(beanName.equals("")){
            beanName=reader.getClasses().getName();
        }

        return beanName;
    }
}
